#include <func.h>

void* thread_func(void *p)
{
    printf("I am child thread\n");
    sleep(1);//等待被cancel
    return NULL;
}

int main()
{
    pthread_t th_id;
    int ret=pthread_create(&th_id,NULL,thread_func,NULL);
    THREAD_ERR_CHECK(ret,"pthread_crat");
    printf("I am main thread\n");

    ret=pthread_cancel(th_id);
    THREAD_ERR_CHECK(ret,"pthread_cancle");
    long thread_ret;//用来接子线程的返回值
    ret=pthread_join(th_id,(void**)&thread_ret);
    THREAD_ERR_CHECK(ret,"pthread_join");

    //注意：回收成功返回的是-1
    printf("I am main thread %ld\n",thread_ret);
    return 0;
}